package com.cn.service.server.ComponentMechanical.Impl;

import com.cn.bean.pojo.ComponentMechanical.OutsourcingResult;
import com.cn.bean.pojo.TechnologicalStandard.GrindingProcessStandardMain;
import com.cn.bean.pojo.bc.MaterList;
import com.cn.bean.pojo.bc.UseDefinition;
import com.cn.bean.pojo.workOrder.GrindingReturnSubTable;
import com.cn.bean.pojo.workOrder.OutsourcingResultMainTable;
import com.cn.bean.pojo.workOrder.OutsourcingResultSubTable;
import com.cn.config.config.Result;
import com.cn.mapper.dao.db1.bc.Mate;
import com.cn.mapper.dao.db1.bc.PurposesDao;
import com.cn.mapper.dao.db5.ComponentMechanical.OutsourcingResultDao;
import com.cn.mapper.dao.db5.PartsManagement.BusinessDepartmentTypeDao;
import com.cn.mapper.dao.db5.TechnologicalStandard.GrindingProcessStandardMainDao;
import com.cn.mapper.dao.db5.sys.Sys_Sequence_Info_TDAO;
import com.cn.service.server.ComponentMechanical.OutsourcingResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class OutsourcingResultServiceImpl implements OutsourcingResultService {
    private final OutsourcingResultDao outsourcingResultDao;
    private final Sys_Sequence_Info_TDAO sysSequenceInfoTdao;
    private final GrindingProcessStandardMainDao grindingProcessStandardMainDao;
    private final PurposesDao purposesDao;
    private final Mate mate;

    @Autowired(required = false)
    public OutsourcingResultServiceImpl(Mate mate, PurposesDao purposesDao, GrindingProcessStandardMainDao grindingProcessStandardMainDao, OutsourcingResultDao outsourcingResultDao, Sys_Sequence_Info_TDAO sysSequenceInfoTdao) {
        this.outsourcingResultDao = outsourcingResultDao;
        this.sysSequenceInfoTdao = sysSequenceInfoTdao;
        this.grindingProcessStandardMainDao = grindingProcessStandardMainDao;
        this.purposesDao = purposesDao;
        this.mate = mate;

    }


    @Override
    public List<OutsourcingResult> selectOutsourcingResultList(int page, int limit, String processName) {
        return outsourcingResultDao.selectOutsourcingResultList(page, limit, processName);
    }

    @Override
    public List<OutsourcingResultSubTable> selectGrindingReturn(OutsourcingResultSubTable outsourcingResultSubTable) {
        return outsourcingResultDao.selectGrindingReturn(outsourcingResultSubTable);
    }

    @Override
    public List<OutsourcingResultSubTable> selectGrindingReturnSub(int id) {
        return outsourcingResultDao.selectGrindingReturnSub(id);
    }

    @Override
    public int insertOutsourcingResultMain(OutsourcingResultMainTable outsourcingResultMainTable) {
        Boolean a = outsourcingResultDao.insertOutsourcingResultMain(outsourcingResultMainTable);
        if (a) {
            return 1;
        }
        return 0;
    }

    @Override
    public int insertOutsourcingResultSub(OutsourcingResultSubTable outsourcingResultSubTable) {
        Boolean b = outsourcingResultDao.insertOutsourcingResultSub(outsourcingResultSubTable);
        if (b) {
            return 1;
        }
        return 0;
    }

    @Override
    public int completeOutsourcingWorkOrde(int workOrderNumber) {
        Boolean c = outsourcingResultDao.completeOutsourcingWorkOrde(workOrderNumber);
        if (c) {
            return 1;
        }
        return 0;
    }

    @Override
    public int insertGrindingReturnSub(GrindingReturnSubTable grindingReturnSubTable) {
        Boolean d = outsourcingResultDao.insertGrindingReturnSub(grindingReturnSubTable);
        if (d) {
            return 1;
        }
        return 0;
    }

    @Override
    public int updateGrindingReturnSub(OutsourcingResultMainTable outsourcingResultMainTable) {
        Boolean e = outsourcingResultDao.updateGrindingReturnSub(outsourcingResultMainTable);
        if (e) {
            return 1;
        }
        return 0;
    }

    @Override
    public int GrindingReturnAudit(int id) {
        Boolean l = outsourcingResultDao.GrindingReturnAudit(id);
        if (l) {
            return 1;
        }
        return 0;
    }

    @Override
    public int updateOutsourcingResultSub(OutsourcingResultSubTable outsourcingResultSubTable) {
        Boolean n = outsourcingResultDao.updateOutsourcingResultSub(outsourcingResultSubTable);
        if (n) {
            return 1;
        }
        return 0;
    }

    @Override
    public int delOutsourcing(int id) {
        Boolean m= outsourcingResultDao.delOutsourcing(id);
        if (m) {
            return 1;
        }
        return 0;
    }

    @Override
    public Integer getOutsourcingResultMainAutoid() {
        return outsourcingResultDao.getOutsourcingResultMainAutoid();
    }

    @Override
    public Integer getOutsourcingResultSubAutoid() {
        return outsourcingResultDao.getOutsourcingResultSubAutoid();
    }

    @Override
    public Integer getGrindingReturnSubTableAutoid() {
        return outsourcingResultDao.getGrindingReturnSubTableAutoid();
    }

    @Override
    public List<GrindingProcessStandardMain> selectGrindingProcessStandard(int id) {
        List<GrindingProcessStandardMain> grindingProcessStandardMains = grindingProcessStandardMainDao.selectGrindingProcessStandardMainId(id);
        GrindingProcessStandardMain firstGrindingProcessStandardMain = grindingProcessStandardMains.get(0);
        List<UseDefinition> useDefinitions = purposesDao.selectUseDefinitionId(firstGrindingProcessStandardMain.getProductPurpose());
        List<MaterList> materLists = mate.selectUseDefinitionId(firstGrindingProcessStandardMain.getMaterial());
//        UseDefinition useDefinition = useDefinitions.get(0);
//        MaterList mater = materLists.get(0);
        if(!useDefinitions.isEmpty()){
            UseDefinition useDefinition = useDefinitions.get(0);
            firstGrindingProcessStandardMain.setProductPurposeName(useDefinition.getYtmc());
        }
        if (!materLists.isEmpty()){
            MaterList mater = materLists.get(0);
            firstGrindingProcessStandardMain.setMaterialName(mater.getYtmc());
        }
//        firstGrindingProcessStandardMain.setProductPurposeName(useDefinition.getYtmc());
//        firstGrindingProcessStandardMain.setMaterialName(mater.getYtmc());
        return grindingProcessStandardMains;
    }

    @Override
    public Result updateOutsourcingResultAutoUniqueCode(List<String> uniqueCodeList) {
        for (String s : uniqueCodeList) {
            int i = outsourcingResultDao.updateOutsourcingResultAutoUniqueCode(s);


        }
        return Result.success("200", "审核成功");
    }
}
